MenuManager - OOP and GUI


代写完成–Java GUI: 菜单管理系统


We are continuing the MenuManager project by adding a class with methods to read information from a File plus inheritance and a Graphical User Interface (GUI) to our MenuManager project.

  1. [5 points] Do not create another project, work in your project [your pitt id]_MenuManager (from last homework). If you lost points for or had errors in that assignment, take care to fix them before moving on.

  2. [12 points] Implement the FileManager class. Methods in this class are static and the class has no fields. We will not create objects of this class, but use its static methods. In UML diagrams, static methods (and static variables) are underlined. FileManager class has methods for reading and writing files. See the figure below.

  • The following method
    public static ArrayList<MenuItem> readItems(String fileName)
    reads all types of dishes from a single file in which each line can be an appetizer, entree, side, or beer. The format of a line in file dishes.txt is
    name of dish@@type of the dish@@description of the dish@@calories@@price
    Where “type of the dish” is either “appetizer”, “entree”, “side”, or “beer” (Take a look to the file included dishes.txt). This “type of the dish” determines what kind of object to create, which class to use: Appetizer, Entree, Side, or Beer. Then the object is added to an ArrayList. Since all these classes extend MenuItem, objects of them can be “treated” generically as MenuItem objects.
  • The method
    public static void writeMenu( String fileName, ArrayList<Menu> menus )
    writes a file (use String fileName parameter) with the information of all the menus in the ArrayList menus. You are free of choosing the format in which the data is written, but for each Menu in the ArrayList, all information should be included: name of the menu, name of each dish, description of each dish, calories and price of each dish, plus the sum of all calories, and the total price.
  1. [18 points] Class MenuItem is defined as the superclass for Appetizer, Entree, Side, and Beer (all these 4 classes extend MenuItem). As a result, the fields and getters/setters previously defined are moved to MenuItem.
  • See the following diagram. Implement the class MenuItem.
  • Make Appetizer, Entree, Side, and Beer classes extend MenuItem (as indicated in the figure) and remove from them all fields and Getters/Setters. The fields name, description, calories are now inherited.
  • Add the field price and the corresponding getter and setter in the class MenuItem. Now all other classes extending MenuItem also inherit price.
  • In all classes Appetizer, Entree, Side, and Beer make constructors to receive all field values and to call the super constructor.
  • Override toString() in MenuItem in order to return the name attribute.
  • Also, override toString() in class Menu (this class is defined in previous Assignment 4) in order to return the name of the menu.
  1. [15 points] Implement the class MenuManager. A MenuManager object has an ArrayList of each of the type of dishes.
  • The constructor, as you can see in the following figure, receives a fileName. Read this file using the method readItems of the class FileManager and fill a single ArrayList of MenuItem. Now we need to separate the single ArrayList containing MenuItem objects into the four ArrayList of different types. To solve this, create the four ArrayList and implement a loop go through the single ArrayList and take every dish and put it in the right ArrayList. Hint: user instanceof operator. You can implement this task in a separate method and call it in the constructor.

  • Implement the method randomMenu. The method creates a Menu object taking randomly one appetizer, one entree, one side, and one beer. The name of the menu is passed in the parameter String name.

  • [Optional: extra credit] Methods minCaloriesMenu() and maxCaloriesMenu() generates the lowest and highest calories menus, respectively. To do the minimum, you have to pick the Entree with the lowest calorie value among entrees. Same for appetizer, side and beer. The method maxCaloriesMenu() do similarly, but selecting highest calories dishes.

  • Add getters and setters to all fields in MenuManager.

  1. [45 points] Graphical User Interface. Build the following GUI.
    FIGURE 1. Main window implemented in class MenuManagerGUI

    FIGURE 2. Secondary window for displaying the details of a Menu, also implemented in MenuManagerGUI class
  • Create the class MenuManagerGUI containing all graphic components and a MenuManager object. Also contains a main(String[] args) method.
  • Declare ALL components (all JLabel, JFrame, JButton, JComboBox, JTextField, etc) as fields in MenuManagerGUI.
  • Make sure you declare a MenuManager object as a field of the MenuManagerGUI class.
  • The constructor of the class MenuManagerGUI should:
    ▪ Create the MenuManager object, which loads the data from the file.
    ▪ Initialize and place all graphic components
    ▪ Load the ArrayLists of MenuManager object into the comboboxes. In other words, fill the comboboxes in the main window with the ArrayList of appetizers, entrees, sides and beers that are contained in the class MenuManager.
  • The execution of the MenuManagerGUI.main method does the following:
    ▪ Creates a MenuManagerGUI object calling the constructor explained before
    ▪ Set the JFrame visible, so the main window appears
  • The main window in the GUI gives you four options to generate Menu objects. These four options correspond to the buttons:
    ▪ “Create Menu with these dishes” button take the selected elements in the four comboboxes and creates a menu. Just before creating the menu object, it asks the user to input a name for the menu. The newly created menu is added to the list at the side.
    ▪ “Generate a Random Menu”: this button asks the user to input a name for the new menu and then uses the method randomMenu in class MenuManager. The random menu generated is then added to the list in the right side.
    ▪ [Optional: extra credit] “Generate a Minimum Calories Menu”: similarly than the previous button but now using the method minCaloriesMenu() from MenuManager.
    ▪ [Optional: extra credit] “Generate a Maximum Calories Menu”: similarly than the previous button but now using the method maxCaloriesMenu() from MenuManager.
  • The list of the right side is where generated menus are placed. The list shows the menus by their names. For achieving this, make sure you override the method toString in class Menu.
  • The button Details (FIGURE 2) displays the secondary window filling all the fields contained there (all textfields and textareas) with the information of the selected Menu in the list of generated menus in the main window (right side in FIGURE 1). Note that the name of the menu selected is in the title of the Details window (FIGURE 2). If no menu is selected in the list, then the secondary window is not shown.
  • The button “Delete all” removes all Menu elements from the list.
  • The button “Save to File” writes a file “data/menus.txt” with the whole data of the menus in the list. Use the method writeMenus from the FileManager class.
  • All text fields in the secondary window (FIGURE 2) are “read only”. This mean their values are filled by the program but the user cannot change them.
  1. [5 points] Correct indentation, naming conventions, and style conventions.